package com.tencreat.account.controller.admin;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tencreat.common.annotation.Log;
import com.tencreat.common.core.HttpResult;
import com.tencreat.common.core.controller.BaseController;
import com.tencreat.common.core.domain.AjaxResult;
import com.tencreat.common.core.domain.model.ReqIdParam;
import com.tencreat.common.core.domain.model.ReqIdsParam;
import com.tencreat.common.enums.BusinessType;
import com.tencreat.common.utils.poi.ExcelUtil;
import com.tencreat.domain.account.AccountWithdrawAudit;
import com.tencreat.domain.account.dto.AdminAuditResultDTO;
import com.tencreat.domain.mall.SupplierWithdrawAudit;
import com.tencreat.domain.mall.vo.AuditResultVO;
import com.tencreat.domain.mall.vo.RrsAuditResultVO;
import com.tencreat.service.account.IAccountWithdrawAuditService;
import com.tencreat.service.account.IAccountWithdrawInfoService;
import com.tencreat.service.account.IMallUserService;
import com.tencreat.service.account.ISupplierWithdrawAuditService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 提现记录Controller
 *
 * @author tencreat
 * @date 2021-11-25
 */
@Api(tags = "提现记录api")
@RestController
@RequestMapping("/mall/audit")
public class AccountWithdrawAuditController extends BaseController {
    @Autowired
    private IAccountWithdrawAuditService accountWithdrawAuditService;

    @Resource
    private IAccountWithdrawInfoService withdrawInfoService;

    @Resource
    private IMallUserService mallUserService;

    @Autowired
    private ISupplierWithdrawAuditService supplierWithdrawAuditService;//供应商提现

    /**
     * 查询提现记录列表
     */
    @ApiOperation(value = "查询提现记录列表")
    @PostMapping("/list")
    public HttpResult<IPage<AccountWithdrawAudit>> list(@RequestBody AccountWithdrawAudit accountWithdrawAudit) {
        return HttpResult.ok(accountWithdrawAuditService.list(accountWithdrawAudit));
    }


    @ApiOperation(value="查询供应商提现记录列表")
//    @PreAuthorize("@ss.hasPermi('system:audit:list')")
    @PostMapping("/supplierList")
    public HttpResult<IPage<SupplierWithdrawAudit>> supplierList(@RequestBody  SupplierWithdrawAudit supplierWithdrawAudit) {
        return HttpResult.ok(supplierWithdrawAuditService.supplierList(supplierWithdrawAudit));
    }

    /**
     * 导出提现记录列表
     */
    @ApiOperation(value = "导出提现记录列表")
    @PreAuthorize("@ss.hasPermi('mall:audit:export')")
    @Log(title = "财务管理>提现审核-余额", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public AjaxResult export(@RequestBody AccountWithdrawAudit accountWithdrawAudit) {
        accountWithdrawAudit.setPageNum(-1);
        accountWithdrawAudit.setPageSize(-1);
        IPage<AccountWithdrawAudit> page = accountWithdrawAuditService.list(accountWithdrawAudit);
        ExcelUtil<AccountWithdrawAudit> util = new ExcelUtil<>(AccountWithdrawAudit.class);
        return util.exportExcel(page.getRecords(), "audit");
    }

    /**
     * 获取提现记录详细信息
     */
    @ApiOperation(value = "获取提现记录详细信息")
    @PreAuthorize("@ss.hasPermi('mall:audit:query')")
    @PostMapping(value = "/getInfo")
    public HttpResult<AccountWithdrawAudit> getInfo(@RequestBody ReqIdParam id) {
        return HttpResult.ok(accountWithdrawAuditService.selectAccountWithdrawAuditById(id));
    }

    /**
     * 新增提现记录
     */
    @ApiOperation(value = "新增提现记录")
    @PreAuthorize("@ss.hasPermi('mall:audit:add')")
    @Log(title = "提现记录", businessType = BusinessType.INSERT)
    @PostMapping(value = "/add")
    public HttpResult<Boolean> add(@RequestBody AccountWithdrawAudit accountWithdrawAudit) {
        return to(accountWithdrawAuditService.insertAccountWithdrawAudit(accountWithdrawAudit));
    }

    /**
     * 修改提现记录
     */
    @ApiOperation(value = "修改提现记录")
    @PreAuthorize("@ss.hasPermi('mall:audit:edit')")
    @Log(title = "提现记录", businessType = BusinessType.UPDATE)
    @PostMapping(value = "/edit")
    public HttpResult<Boolean> edit(@RequestBody AccountWithdrawAudit accountWithdrawAudit) {
        return to(accountWithdrawAuditService.updateAccountWithdrawAudit(accountWithdrawAudit));
    }

    /**
     * 删除提现记录
     */
    @ApiOperation(value = "删除提现记录")
    @PreAuthorize("@ss.hasPermi('mall:audit:remove')")
    @Log(title = "提现记录", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    public HttpResult<Boolean> remove(@RequestBody ReqIdsParam ids) {
        return to(accountWithdrawAuditService.deleteAccountWithdrawAuditByIds(ids));
    }

    @ApiOperation(value = "审核")
    @PostMapping(value = "/auditResult")
    @Log(title = "财务管理>提现审核-余额", businessType = BusinessType.UPDATE)
    public HttpResult<Boolean> auditResult(@RequestBody AdminAuditResultDTO param) {
        accountWithdrawAuditService.auditResult(param);
        return to(true);
    }

    @ApiOperation(value = "金额统计")
    @PostMapping(value = "/statistics")
    public HttpResult<RrsAuditResultVO> statistics() {
        RrsAuditResultVO result = accountWithdrawAuditService.priceStatistics();
        return HttpResult.ok(result);
    }

    @ApiOperation(value = "金额统计(新)")
    @GetMapping(value = "/statisticsV2")
    public HttpResult<AuditResultVO> statisticsV2() {
        AuditResultVO result = accountWithdrawAuditService.priceStatisticsV2();
        return HttpResult.ok(result);
    }
}
